package com.knife.excel;

import org.apache.poi.ss.usermodel.*;

import java.io.File;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * create by yongli on 2021-12-30 10:20
 */

public class ExcelReadTest {
    public static void main(String[] args) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");

        String path = "/Users/yongli/Desktop/风场出质保.xlsx";
        try {
            Workbook workbook = WorkbookFactory.create(new File(path));
            Sheet sheet = workbook.getSheetAt(0);
//            short len = sheet.getDefaultRowHeight();

            int len = sheet.getPhysicalNumberOfRows();
            System.out.println("len:" + len);

            for (int i = 1; i < len; i++) {
                Row row = sheet.getRow(i);
                // 会过滤掉空的cell
//                int width = row.getPhysicalNumberOfCells();
//                int w2 = row.getLastCellNum();
////              System.out.println(width);
////              System.out.println(w2);

                int j = 1;
                Cell cell = row.getCell(j);
                if (cell != null) {
                    // 直接把类型都带出来
//                    double val = cell.getNumericCellValue();
                    System.out.println(cell.getCellType());
                    String val = cell.getStringCellValue();
                    Date date=sdf.parse(val);
                    System.out.println(date);
                } else {
                    System.out.println("null value");
                }

            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
